<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}"/>
    <link th:href="@{/erp/Widget/icheck/icheck.css}" rel="stylesheet" type="text/css"/>
    <!--[if IE 7]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome-ie7.min.css}"/>
    <![endif]-->
    <!--[if lte IE 8]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace-ie.min.css}"/>
    <![endif]-->
    <script th:src="@{/erp/js/jquery-1.9.1.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <script th:src="@{/erp/assets/js/typeahead-bs2.min.js}"></script>
    <!-- page specific plugin scripts -->
    <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/erp/assets/laydate/laydate.js}" type="text/javascript"></script>
    <script type="text/javascript" th:src="@{/erp/Widget/zTree/js/jquery.ztree.all-3.5.min.js}"></script>
    <script th:src="@{/erp/js/lrtk.js}" type="text/javascript"></script>
    <title>物流公司车辆</title>
</head>
<body>
<div class=" page-content clearfix">
    <div id="products_style">
        <div class="search_style">
            <form>
                <ul class="search_content clearfix">
                    <li><label class="l_f">车辆名称</label><input name="vehiclename" type="text" class="text_add"
                                                              placeholder="输入车辆名称" style=" width:250px"/></li>
                    <li><label class="l_f">车牌号</label><input name="number" type="text" class="text_add"
                                                             placeholder="输入车牌号" style=" width:250px"/></li>
                    <li style="width:90px;">
                        <button type="button" class="btn_search" id="selectbyname"><i class="icon-search"></i>查询
                        </button>
                    </li>
                </ul>
            </form>
        </div>
        <div class="border clearfix">
       <span class="l_f">
        <button id="logistic_add" class="btn btn-warning"><i class="icon-plus"></i>添加车辆</button>
       </span>

        </div>

        <table class="table table-striped table-bordered table-hover" id="sample-table">
            <thead>
            <tr>
                <th style='display:none' width="100px">车辆ID</th>
                <th width="100px">车辆编号</th>
                <th width="150px">车辆名称</th>
                <th width="100px">车牌号</th>
                <th width="100px">车辆类型</th>
                <th style='display:none' width="150px">所属物流公司ID</th>
                <th width="150px">所属物流公司</th>
                <th style='display:none' width="80px">驾驶员ID</th>
                <th width="80px">驾驶员</th>
                <th width="100px">车辆载重量(T)</th>
                <th width="100px">尺寸(L/W/H)</th>
                <th width="150px">操作</th>

            </tr>
            </thead>
            <tbody>


            </tbody>
        </table>
    </div>
</div>
</div>
</div>
<!--添加车辆图层-->
<div class="add_menber" id="add_menber_style" style="display:none">

    <ul class=" page-content">
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*车辆名称：</label>
            <div class="formControls ">
                <input type="text" onchange="writegz(this)" class="input-text" value="" placeholder="" id="vehicleNameadd" name="车辆名称">
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*物流公司：&nbsp;</label>
            <div class="formControls ">
                <select class="select" id="logisticsnameadd" style="margin-left:10px">
                    <option value="1">请选择</option>
                </select>
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*驾驶员姓名：&nbsp;</label>
            <div class="formControls ">
                <select class="select" id="driverNameadd" style="margin-left:10px">
                    <option value="1">请选择</option>
                </select>
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*车牌号：</label>
            <div class="formControls ">
                <input type="text" onchange="numberPlate(this)" class="input-text" value="" placeholder="" id="numberPlatebjadd" name="车牌号">
            </div>
        </div>


        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*车辆类型：</label>
            <div class="formControls ">
                <input type="text" onchange="writegz(this)" class="input-text" value="" placeholder="" id="vehicleTypeadd" name="车辆类型">
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*车辆载重：</label>
            <div class="formControls ">
                <input type="text" onchange="numbergz(this)" class="input-text" value="" placeholder="" id="driverCapacityadd" name="车辆载重">
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*尺寸（L/W/H）：</label>
            <div class="formControls ">
                <input type="text" onchange="ckg(this)" class="input-text" value="" placeholder="" id="driverSizeadd" name="尺寸">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label">*备注：</label>
            <div class="formControls">
                <textarea name="" rows="" id="remarksadd" class="textarea" placeholder="说点什么...最少输入10个字符"
                          datatype="*10-100" maxlength="120"
                          dragonfly="true" nullmsg="备注不能为空！"></textarea>

            </div>
        </div>
        <div class="">
            <div class="" style=" text-align:center">
            </div>
        </div>

    </ul>
</div>

</div>
</div>
</div>
</div>
</div>
<!--编辑属性图层-->
<div class="edit_menber" id="edit_menber_style" style="display:none">
    <ul class=" page-content">
        <div class="formControls" style="display:none">
            <input type="text" class="input-text" value="" placeholder="" id="vehicleIdbj" name="车辆ID">
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red" id=""></span>车辆名称：</label>
            <div class="formControls ">
                <input type="text" onchange="writegz(this)" class="input-text" value="" placeholder="" id="vehicleNamebj" name="车辆名称">
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>物流公司：&nbsp;</label>
            <div class="formControls ">
                <select id="logisticsnamebj" class="select" style="margin-left:10px">
                    <option>请选择</option>
                </select>
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>驾驶员：&nbsp;</label>
            <div class="formControls ">
                <select id="driverNamebj" class="select" style="margin-left:10px">
                    <option>请选择</option>
                </select>
            </div>
        </div>


        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>车牌号：</label>
            <div class="formControls ">
                <input type="text" onchange="numberPlate(this)" class="input-text" value=" " placeholder="" id="numberPlatebj" name="车牌号">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>车辆类型：</label>
            <div class="formControls ">
                <input type="text" onchange="writegz(this)" class="input-text" value="" placeholder="" id="vehicleTypebj" name="车辆类型">
            </div>
        </div>


        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>尺寸（L/W/H）：</label>
            <div class="formControls ">
                <input type="text" onchange="ckg(this)" class="input-text" value="4.2*1.9*1.8" placeholder="" id="driverSizebj" name="尺寸">
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label">备注：</label>
            <div class="formControls">
                <textarea name="" rows="" class="textarea" id="remarksbj" maxlength="120" placeholder="说点什么...最少输入10个字符"
                          datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！" ></textarea>

            </div>
        </div>
        <div class=""/>
        <div class="" style=" text-align:center"/>
    </ul>
</div>
<script type="text/javascript" th:src="@{/js/regularExpression.js}"></script>
<script type="text/javascript" th:src="@{/js/l_d.js}"></script>
</body>
</html>
<script>
    /*物流公司-添加*/
    $('#logistic_add').on('click', function () {
        layer.open({
            type: 1,
            title: '添加车辆',
            maxmin: true,
            shadeClose: true, //点击遮罩关闭层
            area: ['600px', ''],
            content: $('#add_menber_style'),
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var num = 0;
                var str = "";
                $(".add_menber input[type$='text']").each(function (n) {
                    if ($(this).val() == "") {

                        layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        });
                        num++;
                        return false;
                    }
                });
                if ($('#logisticsnameadd').val() == "1") {

                    layer.alert( "物流公司不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        }
                    );
                    num++;
                    return false;
                }
                if ($('#driverNameadd').val() == "1") {

                    layer.alert( "驾驶员不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        }
                    );
                    num++;
                    return false;
                }
                if (num > 0) {
                    return false;
                } else {
                    $.ajax({
                        data: {
                            "vehicleName": document.getElementById('vehicleNameadd').value
                            , "logisticsId": document.getElementById('logisticsnameadd').value
                            , "driverId": document.getElementById('driverNameadd').value
                            , "numberPlate": document.getElementById('numberPlatebjadd').value
                            , "vehicleType": document.getElementById('vehicleTypeadd').value
                            , "driverSize": document.getElementById('driverSizeadd').value
                            , "driverCapacity": document.getElementById('driverCapacityadd').value
                            , "remarks": document.getElementById('remarksbj').value
                        },
                        type: 'post',
                        dataType: 'josn',
                        url: '/vehicle/addvehicle',
                        success: function (data) {
                            alert(data);
                            if(!data.rs){
                                layer.msg(data.msg,{icon:2,time:2000})
                            }
                        }

                    });

                    layer.alert('添加成功！', {
                        title: '提示框',
                        icon: 1,
                    });
                    layer.close(index);
                    window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
                }
            }
        });
    });

    /*车辆公司信息-编辑*/
    function member_edit(e) {
        var id = $(e).parent().parent().children("td:eq(0)").text();
        var logisticsid = $(e).parent().parent().children("td:eq(5)").text();
        var driverid = $(e).parent().parent().children("td:eq(7)").text();
        var driverCapacity = $(e).parent().parent().children("td:eq(9)").text();
        document.getElementById('vehicleNamebj').value = $(e).parent().parent().children("td:eq(2)").text();
        document.getElementById('numberPlatebj').value = $(e).parent().parent().children("td:eq(3)").text();
        document.getElementById('vehicleTypebj').value = $(e).parent().parent().children("td:eq(4)").text();
        document.getElementById('driverSizebj').value = $(e).parent().parent().children("td:eq(10)").text();
        document.getElementById('vehicleIdbj').value = $(e).parent().parent().children("td:eq(0)").text();


        console.log(driverid);
        //$('#logisticsnamebj option').not(":first").remove();
        $.ajax({
            url: '[[@{/logisticsxx/alllogistics}]]',
            success: function (data) {
                console.log(data);
                if(data.rs) {
                    var d=data.data;
                    for (var i in d) {
                        if (logisticsid == d[i].logisticsId) {
                            $('#logisticsnamebj:last').append("<option selected = \"selected\" value=" + d[i].logisticsId + ">   " + d[i].logisticsName + "</option>")
                        } else {
                            $('#logisticsnamebj:last').append("<option value=" + d[i].logisticsId + ">" + d[i].logisticsName + "</option>")
                        }
                    }
                }else {
                    layer.msg(data.msg,{icon:2,time:2000});
                }

            }

        })

        $.ajax({
            url: '[[@{/driver/findalldriver}]]',
            success: function (data) {
                console.log(data);
                if(data.rs) {
                    var d=data.data;
                    for (var i in d) {
                        if (driverid == data[i].driverId) {
                            $('#driverNamebj:last').append("<option selected = \"selected\" value=" + d[i].driverId + ">" + d[i].driverName + "</option>")
                        } else {
                            $('#driverNamebj:last').append("<option value=" + d[i].driverId + ">" + d[i].driverName + "</option>")
                        }
                    }
                }else {
                    layer.msg(data.msg,{icon:2,time:2000});
                }

            }

        })

        $.ajax({
            data: {"id": id},
            type: 'post',
            dataType: 'json',
            url: '/vehicle/findremarks',
            success: function (data) {
                if(data.rs) {
                    console.log("返回成功");
                    console.log(data);
                    var d = data.data;
                    document.getElementById('remarksbj').value = d;
                }else {
                    layer.msg(data.msg,{icon:2,time:2000});
                }
            }
        });
        layer.open({
            type: 1,
            title: '修改车辆信息',
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area: ['600px', ''],
            content: $('#edit_menber_style'),
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var num = 0;
                var str = "";
                $(".edit_menber input[type$='text']").each(function (n) {
                    if ($(this).val() == "") {

                        layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        });
                        num++;
                        return false;
                    }
                });
                if (num > 0) {
                    return false;
                } else {
                    $.ajax({
                        data: {
                            "vehicleId": document.getElementById('vehicleIdbj').value
                            , "vehicleName": document.getElementById('vehicleNamebj').value
                            , "logisticsId": document.getElementById('logisticsnamebj').value
                            , "driverId": document.getElementById('driverNamebj').value
                            , "numberPlate": document.getElementById('numberPlatebj').value
                            , "vehicleType": document.getElementById('vehicleTypebj').value
                            , "driverSize": document.getElementById('driverSizebj').value
                            , "driverCapacity": driverCapacity
                            , "remarks": document.getElementById('remarksbj').value
                        },
                        type: 'post',
                        dataType: 'josn',
                        url: '/vehicle/updatevehicle',
                        success: function (data) {
                            console.log(data);
                            if(!data.rs){
                                layer.msg(data.msg,{icon:2,time:2000})
                            }
                        }
                    });

                    layer.alert('修改成功！', {
                        title: '提示框',
                        icon: 1,
                    });
                    layer.close(index);
                    window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
                }
            }
        });
    }

    jQuery(function ($) {


        var oTable1 = $('#sample-table').dataTable({
            searching: false,
            serverSide: true,
            ajax: {
                url: '/vehicle/findAll',
                type: 'post',
                data: function (d) {
                    var data = $('form').serialize();
                    var searchParame = {
                        start: d.start,
                        length: d.length,
                    };
                    data = data + '&' + $.param(searchParame);
                    return data;
                }
            },


            columns: [
                {"data": "vehicleId", "className": "hidden"},
                {
                    "data": "vehicleId", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append(row + 1)
                    }
                },
                {"data": "vehicleName"},
                {"data": "numberPlate"},
                {"data": "vehicleType"},
                {"data": "logisticsId", "className": "hidden"},
                {"data": "logisticsName"},
                {"data": "driverId", "className": "hidden"},
                {"data": "driverName"},
                {"data": "driverCapacity"},
                {"data": "driverSize"},
                {
                    "data": "logisticsId", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append(' <a title="编辑" onclick="member_edit(this)" href="javascript:;"  class="btn btn-xs btn-info" ><i class="icon-edit bigger-120"></i></a> \n' +

                            '                    <a title="删除" href="javascript:;"  onclick="member_del(this,\'1\')" \n' +
                            'class="btn btn-xs btn-warning" ><i class="icon-trash bigger-120"></i></a>')
                    }
                },

            ]
        })

        /*搜索*/
        $('#selectbyname').click(function () {
            oTable1.fnUpdate();
        })


    });


</script>
<script type="text/javascript">


    /*删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            var ids = $(obj).parent().parent().children("td:eq(0)").text();
            console.log(ids);
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {"id": ids},
                url: '/vehicle/deletevehicle',
                success: function (data) {
                    alert(data);
                    if(!data.rs){
                        layer.msg(data.msg,{icon:2,time:2000})
                    }
                }
            })
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
            window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
        });
    }


</script>
